package com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.service.impl;

import cn.hutool.core.date.DateUtil;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.dto.ListClockDataDTO;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.dto.PageRelatedInoutstatDTO;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.service.RelatedInoutstatService;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.vo.RelatedClockVO;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.vo.RelatedInoutstatPageVO;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.inoutstat.vo.RelatedInoutstatVO;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.lwt071relatedpartiesperson.service.Lwt071RelatedPartiesPersonService;
import com.jxdinfo.hussar.cloud.module.labor.xgfgl.lwt073attrelpartpersonclock.service.Lwt073AttRelPartPersonClockService;
import com.jxdinfo.hussar.support.datasource.annotations.HussarDs;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 相关方人员进出统计service实现
 * @author cx
 */
@Service("xgfgl.inoutstat.InoutstatServiceImpl")
@HussarDs("master")
public class RelatedInoutstatServiceImpl implements RelatedInoutstatService {

    /**
     * 相关方人员service
     */
    @Resource
    private Lwt071RelatedPartiesPersonService lwt071RelatedPartiesPersonService;
    /**
     * 相关方人员打卡记录service
     */
    @Resource
    private Lwt073AttRelPartPersonClockService lwt073AttRelPartPersonClockService;

    /**
     * 相关方人员进出统计列表(分页查询)
     * @param dto
     * @return
     */
    @Override
    public RelatedInoutstatPageVO pageRelatedInoutstat(PageRelatedInoutstatDTO dto) {

        RelatedInoutstatPageVO result = new RelatedInoutstatPageVO();

        Date now = new Date();

        // TODO 这边后面要使用ES, 这边先返回假数据
        List<RelatedInoutstatVO> statVOList = Arrays.asList(
                RelatedInoutstatVO.builder().relPartPersonId("1").name("张三").idCard("370951200002021355").mobile("13292323352").relatedPartiesName("山东不诚信工程建设监理有限公司").earliestInTime(DateUtils.addHours(now, -3)).latestOutTime(now).build(),
                RelatedInoutstatVO.builder().relPartPersonId("2").name("李四").idCard("370951199902021355").mobile("13298565462").relatedPartiesName("山东不太诚信工程建设监理有限公司").earliestInTime(DateUtils.addHours(now, -5)).latestOutTime(now).build(),
                RelatedInoutstatVO.builder().relPartPersonId("3").name("老五").idCard("370951199802021353").mobile("18566658952").relatedPartiesName("山东不怎么诚信工程建设监理有限公司").earliestInTime(DateUtils.addHours(now, -6)).latestOutTime(now).build(),
                RelatedInoutstatVO.builder().relPartPersonId("4").name("老六").idCard("370951199702021355").mobile("13856664552").relatedPartiesName("山东不想诚信工程建设监理有限公司").earliestInTime(DateUtils.addHours(now, -1)).latestOutTime(now).build()
        );

        result.setData(statVOList);
        result.setCount(statVOList.size());

        return result;
    }

    /**
     * 查询相关方人员的打卡记录数据
     * @param dto
     * @return
     */
    @Override
    public List<RelatedClockVO> listClockData(ListClockDataDTO dto) {
        // TODO 打卡数据后期存ES, 这里暂时先返回假数据
        Date now = new Date();
        Random random = new Random();
        List<RelatedClockVO> list = Arrays.asList(
                new RelatedClockVO(now,"闸机A","施工区","出场"),
                new RelatedClockVO(DateUtils.addHours(now, 0 - random.nextInt(5) - 1),"闸机B","施工区","入场")
        );
        return list;
    }
}
